Home:ALL Converter>postgresql return error : ERROR: canceling statement due to user request

postgresql return error : ERROR: canceling statement due to user request

Ask Time:2020-06-27T17:48:16         Author:stkflmb12

Json Formatter

I'm using postgresql 9.6,it's ok to execute in psql command:

  select pg_cancel_backend(a.pid)  from pg_locks a join pg_class b on a.relation = b.oid join pg_stat_activity c on a.pid = c.pid where c.datname = 'mydb' and a.mode like '%AccessShareLock%'; 

However, it prompts an error : "ERROR: canceling statement due to user request" when I execute the following scripts:

/app/postgres/pgsql/bin/psql -h "127.0.0.1" -p 6661 -U "postgres" -d "mydb" -tc "select pg_cancel_backend(a.pid)  from pg_locks a
> join pg_class b on a.relation = b.oid
> join pg_stat_activity c on a.pid = c.pid
> where c.datname = 'mydb' and a.mode like '%AccessShareLock%';"

what is the difference between this two methods?

enter image description here

Author:stkflmb12,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/62608428/postgresql-return-error-error-canceling-statement-due-to-user-request
yy